// ============================== 导入依赖 ============================== //

import Vue from 'vue'
import API from './API'

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 下拉框 —————————————————————————————— //

  async remoteSelect({ state: { info, selectParam: { deviceId }, SELECT_FIELD } }) {
    deviceId.forEach((id) => {
      API.getSelect({ deviceId: id })
        .then((select) => { // 成功
          Vue.set(info, id, transDict(select, SELECT_FIELD))
        }).catch(() => { // 失败
          Vue.set(info, id, [])
        })
    })
  },
}

// ============================== 转换方法 ============================== //

const transDict = (select, SELECT_FIELD) => select.map((item) => SELECT_FIELD.map((field) => item[field]))
